const chalk = require("chalk")

function setProxy(proxyObjs, objName) {
    const handler = {
        get(target, property, receiver) {
            switch (property) {
                case "Math":
                case "encodeURI":
                case "isNaN":
                case "Uint8Array":
                    return Reflect.get(target, property, receiver);
            }
            let value;
            switch (Object.prototype.toString.call(target[property])) {
                case "[object global]":
                    value = Object.prototype.toString.call(target[property])
                    break;
                case "[object Undefined]":
                    value = chalk.red(target[property])
                    break
                default:
                    value = target[property]
            }

            console.log(
                chalk.yellow("[GET]"),
                "对象:", objName,
                "属性名:", property,
                "属性类型:", Object.prototype.toString.call(property),
                "属性值:", value,
                "属性值类型:", Object.prototype.toString.call(target[property])
            );
            return Reflect.get(target, property, receiver);
        },
        set(target, property, value, receiver) {
            console.log(
                chalk.blue("[SET]"),
                "对象:", objName,
                "属性名:", property,
                "属性类型:", Object.prototype.toString.call(property),
                "属性值:", value,
                "属性值类型:", Object.prototype.toString.call(value)
            );
            return Reflect.set(target, property, value, receiver)
        }
    };

    return new Proxy(proxyObjs, handler)

}


window = setProxy(globalThis, "window");
CanvasRenderingContext2D = function () {
    console.log(
        chalk.red("[CALL]"),
        "方法:", "CanvasRenderingContext2D",
        "参数:", arguments,
    );
}
CanvasRenderingContext2D = setProxy(CanvasRenderingContext2D, "CanvasRenderingContext2D");

two = new CanvasRenderingContext2D()

let number
HTMLCanvasElement = function () {
    console.log(
        chalk.red("[CALL]"),
        "方法:", "HTMLCanvasElement",
        "参数:", arguments,
    );
    this.getContext = function () {
        console.log(
            chalk.red("[CALL]"),
            "方法:", "getContext",
            "参数:", arguments,
        );
        if (arguments[0] == "2d") {
            return two
        }
    }
    this.setAttribute = function () {
        console.log(
            chalk.red("[CALL]"),
            "方法:", "setAttribute",
            "参数:", arguments,
        );
    }
    this.toDataURL = function () {
        console.log(
            chalk.red("[CALL]"),
            "方法:", "toDataURL",
            "参数:", arguments,
        );
        if (number == 1) {
            number += 1
            return ``
        }
        if (number == 2) {
            return ""
        }

    }
}
HTMLCanvasElement = setProxy(HTMLCanvasElement, "HTMLCanvasElement");

screen = {
    availHeight: 1032,
    availLeft: 0,
    availTop: 0,
    availWidth: 1920,
    colorDepth: 24,
    height: 1080,
    isExtended: false,
    onchange: null,
    pixelDepth: 24,
    width: 1920,
}
window.screen = setProxy(screen, "screen")






let canvas = new HTMLCanvasElement()


// HTMLDocument = function () { }
// HTMLDocument.prototype.createElement = function createElement() {
//     console.log(
//         chalk.red("[CALL]"),
//         "方法:", "createElement",
//         "参数:", arguments,
//     );
//     if (arguments[0] === "canvas") {
//         return setProxy(canvas, "canvas")
//     }

// }

// HTMLDocument.prototype.createElement.toString = function toString() {
//     return 'function createElement() { [native code] }'
// }

// HTMLDocument.prototype.toString = function toString() {
//     return '[object HTMLDocument]'
// }

// document = setProxy(new HTMLDocument(), "document")
document = setProxy({}, "document")
createElement = function createElement() {
    console.log(
        chalk.red("[CALL]"),
        "方法:", "createElement",
        "参数:", arguments,
    );
    if (arguments[0] === "canvas") {
        return setProxy(canvas, "canvas")
    }
}
document.createElement = createElement

document.cookie = `ibulanguage=HK; ibulocale=zh_hk; UBT_VID=1744269722470.3595LWgSFeja; _abtest_userid=50778cc3-f6f7-4ab8-883c-081364fb83e3; devicePixelRatio=1; _gcl_au=1.1.188064183.1744269840; _gid=GA1.2.931935782.1744269840; _fwb=140sk81QXL0MTeWVOT8Dm2U.1744269841299; _tt_enable_cookie=1; _ttp=01JRF9B5MA5QJRWBTPXF3D0164_.tt.1; _fbp=fb.1.1744269844813.826090906869440683; ibu_online_permission_cls_ct=1; ibu_online_permission_cls_gap=1744269977747; ibu_online_jump_site_result={"site_url":[],"suggestion":[]}; ibu_country=HK; _RF1=2607%3Af130%3A0%3A145%3A%3Aced2%3A8326; _RSG=Kx4wZPKCU35TBP.MAyRIa8; _RDG=283f9e8493972d24f1196e8f758f1e5cfa; _RGUID=50de3146-63e8-4ed4-8912-6fc296f992dd; g_state={"i_p":1744378632638,"i_l":2}; ibu_pwa_insvisit=%7B%22vid%22%3A%221744269722470.3595LWgSFeja%22%2C%22time%22%3A1744292219021%7D; Union=AllianceID=849555&SID=1415694&OUID=ctag.hash.tmawf3tohaa2&Expires=1746884379098&createtime=1744292379; _gac_UA-109672825-1=1.1744292488.Cj0KCQjw2N2_BhCAARIsAK4pEkVeqZGW4PbXLthdLy-fb8v01hb7qSRjy8mugoeBA0TmMwllARLZiyUaAhA8EALw_wcB; _gcl_gs=2.1.k1$i1744292485$u30159398; _gac_UA-109672825-3=1.1744292488.Cj0KCQjw2N2_BhCAARIsAK4pEkVeqZGW4PbXLthdLy-fb8v01hb7qSRjy8mugoeBA0TmMwllARLZiyUaAhA8EALw_wcB; _gcl_aw=GCL.1744292490.Cj0KCQjw2N2_BhCAARIsAK4pEkVeqZGW4PbXLthdLy-fb8v01hb7qSRjy8mugoeBA0TmMwllARLZiyUaAhA8EALw_wcB; ubtc_trip_pwa=0; _tp_search_latest_channel_name=flights; ibu_oh_pp_exposed=1; cookiePricesDisplayed=HKD; nfes_isSupportWebP=1; nfes_isSupportWebP=1; ibu_hotel_search_date=%7B%22checkIn%22%3A%222025%2F04%2F11%22%2C%22checkOut%22%3A%222025%2F05%2F05%22%7D; ibu_hotel_search_target=%7B%22countryId%22%3A1%2C%22provinceId%22%3A0%2C%22searchWord%22%3A%22%E6%B7%B1%E5%9C%B3%22%2C%22cityId%22%3A30%2C%22searchType%22%3A%22CT%22%7D; __utmz=1.1744293928.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); _gac_UA-109672825-1=1.1744292488.Cj0KCQjw2N2_BhCAARIsAK4pEkVeqZGW4PbXLthdLy-fb8v01hb7qSRjy8mugoeBA0TmMwllARLZiyUaAhA8EALw_wcB; ibu_online_home_language_match={"isRedirect":false,"isShowSuggestion":false,"lastVisited":true,"region":"us","redirectSymbol":false}; trip_test_cookie=1; _combined=transactionId%3D1-mf-20250411002925029-nodejs%26pageId%3D10320667453%26initPageId%3D10320667453; GUID=09034073116477340659; trn_traffic_start=10650138510; trn_traffic_end=10650138510; ibu_car_channelid=14409; _pd=%7B%22_o%22%3A17%2C%22s%22%3A24%2C%22_s%22%3A0%7D; __utma=1.1336250925.1744269840.1744293928.1744302731.2; __utmc=1; _ga_37RNVFDP1J=GS1.2.1744302674.3.1.1744302738.60.0.0; IBU_TRANCE_LOG_P=87772816003; oldLocale=zh-HK; ibu_hotel_search_crn_guest=%7B%22adult%22%3A%222%22%2C%22children%22%3A%220%22%2C%22ages%22%3A%22%22%2C%22crn%22%3A%221%22%7D; _bfa=1.1744269722470.3595LWgSFeja.1.1744302746053.1744303792577.5.13.10320668148; IBU_showtotalamt=0; _uetsid=c603a9a015dc11f09485af91c9d176ee; _uetvid=c603df8015dc11f08e609db5bae96301; ttcsid=1744302675521.5.1744303877378; wcs_bt=s_33fb334966e9:1744303877; ttcsid_CIR4RVBC77UD5V58BBNG=1744302675520.5.1744303877609; _ga=GA1.1.1336250925.1744269840; _ga_X437DZ73MR=GS1.1.1744302674.5.1.1744303876.60.0.0; _ga_2DCSB93KS4=GS1.2.1744302674.5.1.1744303877.60.0.0`,


    location = setProxy({
        "ancestorOrigins": {},
        "href": "https://hk.trip.com/hotels/list?city=30&cityName=%E6%B7%B1%E5%9C%B3&provinceId=0&countryId=1&districtId=0&checkin=2025%2F04%2F11&checkout=2025%2F05%2F05&lowPrice=0&highPrice=-1&barCurr=HKD&searchType=CT&searchWord=%E6%B7%B1%E5%9C%B3&crn=1&adult=2&children=0&searchBoxArg=t&travelPurpose=0&ctm_ref=ix_sb_dl&domestic=true&listFilters=29%7C1*29*1%7C2*2&locale=zh-HK&curr=HKD",
        "origin": "https://hk.trip.com",
        "protocol": "https:",
        "host": "hk.trip.com",
        "hostname": "hk.trip.com",
        "port": "",
        "pathname": "/hotels/list",
        "search": "?city=30&cityName=%E6%B7%B1%E5%9C%B3&provinceId=0&countryId=1&districtId=0&checkin=2025%2F04%2F11&checkout=2025%2F05%2F05&lowPrice=0&highPrice=-1&barCurr=HKD&searchType=CT&searchWord=%E6%B7%B1%E5%9C%B3&crn=1&adult=2&children=0&searchBoxArg=t&travelPurpose=0&ctm_ref=ix_sb_dl&domestic=true&listFilters=29%7C1*29*1%7C2*2&locale=zh-HK&curr=HKD",
        "hash": ""
    }, "location")



require("./trip2.js")



let data = {
    "guideLogin": "T",
    "search": {
        "sessionId": "70c576de-96c6-945a-bb6d-fc0fa44dd1bc",
        "preHotelCount": 23,
        "preHotelIds": [
            115996086,
            456133,
            120441830,
            70797786,
            100589920,
            103066319,
            97711372,
            1426490,
            34998429,
            1596525,
            1519714,
            420085,
            111774115,
            83647767,
            2247932,
            115825601,
            21826582,
            345032,
            114658239,
            102556928,
            347428,
            104615137,
            69427186
        ],
        "checkIn": "20250411",
        "checkOut": "20250505",
        "sourceFromTag": "",
        "filters": [
            {
                "filterId": "29|1",
                "type": "29",
                "value": "1|2",
                "subType": "2"
            },
            {
                "filterId": "17|1",
                "type": "17",
                "value": "1",
                "subType": "2"
            },
            {
                "filterId": "80|0|1",
                "type": "80",
                "value": "0",
                "subType": "2"
            }
        ],
        "pageCode": 10320668148,
        "location": {
            "geo": {
                "countryID": 1,
                "provinceID": 0,
                "cityID": 30,
                "districtID": 0,
                "oversea": false
            },
            "coordinates": []
        },
        "pageIndex": 3,
        "pageSize": 10,
        "needTagMerge": "T",
        "roomQuantity": 1,
        "orderFieldSelectedByUser": false,
        "hotelId": 0,
        "hotelIds": [],
        "lat": 22.536674277945078,
        "lng": 114.06165334380388,
        "tripWalkDriveSwitch": "T",
        "resultType": "CT",
        "nearbyHotHotel": {},
        "recommendTimes": 0,
        "crossPromotionId": "",
        "travellingForWork": false
    },
    "batchRefresh": {
        "batchId": "",
        "batchSeqNo": 0
    },
    "queryTag": "NORMAL",
    "mapType": "GOOGLE",
    "extends": {
        "crossPriceConsistencyLog": "",
        "NewTaxDescForAmountshowtype0": "B",
        "TaxDescForAmountshowtype2": "T",
        "MealTagDependOnMealType": "T",
        "MultiMainHotelPics": "T",
        "enableDynamicRefresh": "T",
        "isFirstDynamicRefresh": "T",
        "ExposeBedInfos": "F",
        "TaxDescRemoveRoomNight": "",
        "priceMaskLoginTip": "",
        "NeedHotelHighLight": "T"
    },
    "head": {
        "platform": "PC",
        "clientId": "1744269722470.3595LWgSFeja",
        "bu": "ibu",
        "group": "TRIP",
        "aid": "849555",
        "sid": "1415694",
        "ouid": "ctag.hash.tmawf3tohaa2",
        "caid": "849555",
        "csid": "1415694",
        "couid": "ctag.hash.tmawf3tohaa2",
        "region": "HK",
        "locale": "zh-HK",
        "timeZone": "8",
        "currency": "HKD",
        "p": "87772816003",
        "pageID": "10320668148",
        "deviceID": "PC",
        "clientVersion": "0",
        "frontend": {
            "vid": "1744269722470.3595LWgSFeja",
            "sessionID": "6",
            "pvid": "3"
        },
        "extension": [
            {
                "name": "cityId",
                "value": "30"
            },
            {
                "name": "checkIn",
                "value": "2025/04/11"
            },
            {
                "name": "checkOut",
                "value": "2025/05/05"
            },
            {
                "name": "region",
                "value": "HK"
            }
        ],
        "tripSub1": "",
        "qid": "435921893385",
        "pid": "e867b696-5bdd-421e-b4ae-3340678fe671",
        "hotelExtension": {},
        "cid": "1744269722470.3595LWgSFeja",
        "traceLogID": "6e28e63521e128",
        "ticket": "",
        "href": "https://hk.trip.com/hotels/list?city=30&cityName=%E6%B7%B1%E5%9C%B3&provinceId=0&countryId=1&districtId=0&checkin=2025%2F04%2F11&checkout=2025%2F05%2F05&lowPrice=0&highPrice=-1&barCurr=HKD&searchType=CT&searchWord=%E6%B7%B1%E5%9C%B3&crn=1&adult=2&children=0&searchBoxArg=t&travelPurpose=0&ctm_ref=ix_sb_dl&domestic=true&listFilters=29%7C1*29*1%7C2*2&locale=zh-HK&curr=HKD",
        "deviceConfig": "L"
    }
}

let O = window.signature(data);
console.log(O, O.length);





fetch("https://hk.trip.com/htls/getHotelListDynamicRefresh?x-traceID=1744269722470.3595LWgSFeja-1744303873371-1315100730", {
    "headers": {
        "accept": "application/json",
        "accept-language": "zh-CN,zh;q=0.9,en;q=0.8",
        "cache-control": "no-cache",
        "content-type": "application/json",
        "currency": "HKD",
        "locale": "zh-HK",
        "p": "87772816003",
        "phantom-token": O,
        "pid": "3498e6fc-7ae9-47a9-a5e9-43c92ff1f9ae",
        "pragma": "no-cache",
        "priority": "u=1, i",
        "sec-ch-ua": "\"Google Chrome\";v=\"135\", \"Not-A.Brand\";v=\"8\", \"Chromium\";v=\"135\"",
        "sec-ch-ua-mobile": "?0",
        "sec-ch-ua-platform": "\"Windows\"",
        "sec-fetch-dest": "empty",
        "sec-fetch-mode": "cors",
        "sec-fetch-site": "same-origin",
        "trip-trace-id": "1744269722470.3595LWgSFeja-1744303873371-1315100730",
        "x-traceid": "1744269722470.3595LWgSFeja-1744303873371-1315100730",
        "cookie": "ibulanguage=HK; ibulocale=zh_hk; UBT_VID=1744269722470.3595LWgSFeja; _abtest_userid=50778cc3-f6f7-4ab8-883c-081364fb83e3; devicePixelRatio=1; _gcl_au=1.1.188064183.1744269840; _gid=GA1.2.931935782.1744269840; _fwb=140sk81QXL0MTeWVOT8Dm2U.1744269841299; _tt_enable_cookie=1; _ttp=01JRF9B5MA5QJRWBTPXF3D0164_.tt.1; _fbp=fb.1.1744269844813.826090906869440683; ibu_online_permission_cls_ct=1; ibu_online_permission_cls_gap=1744269977747; ibu_online_jump_site_result={\"site_url\":[],\"suggestion\":[]}; ibu_country=HK; _RF1=2607%3Af130%3A0%3A145%3A%3Aced2%3A8326; _RSG=Kx4wZPKCU35TBP.MAyRIa8; _RDG=283f9e8493972d24f1196e8f758f1e5cfa; _RGUID=50de3146-63e8-4ed4-8912-6fc296f992dd; g_state={\"i_p\":1744378632638,\"i_l\":2}; ibu_pwa_insvisit=%7B%22vid%22%3A%221744269722470.3595LWgSFeja%22%2C%22time%22%3A1744292219021%7D; Union=AllianceID=849555&SID=1415694&OUID=ctag.hash.tmawf3tohaa2&Expires=1746884379098&createtime=1744292379; _gac_UA-109672825-1=1.1744292488.Cj0KCQjw2N2_BhCAARIsAK4pEkVeqZGW4PbXLthdLy-fb8v01hb7qSRjy8mugoeBA0TmMwllARLZiyUaAhA8EALw_wcB; _gcl_gs=2.1.k1$i1744292485$u30159398; _gac_UA-109672825-3=1.1744292488.Cj0KCQjw2N2_BhCAARIsAK4pEkVeqZGW4PbXLthdLy-fb8v01hb7qSRjy8mugoeBA0TmMwllARLZiyUaAhA8EALw_wcB; _gcl_aw=GCL.1744292490.Cj0KCQjw2N2_BhCAARIsAK4pEkVeqZGW4PbXLthdLy-fb8v01hb7qSRjy8mugoeBA0TmMwllARLZiyUaAhA8EALw_wcB; ubtc_trip_pwa=0; _tp_search_latest_channel_name=flights; ibu_oh_pp_exposed=1; cookiePricesDisplayed=HKD; nfes_isSupportWebP=1; nfes_isSupportWebP=1; ibu_hotel_search_date=%7B%22checkIn%22%3A%222025%2F04%2F11%22%2C%22checkOut%22%3A%222025%2F05%2F05%22%7D; ibu_hotel_search_target=%7B%22countryId%22%3A1%2C%22provinceId%22%3A0%2C%22searchWord%22%3A%22%E6%B7%B1%E5%9C%B3%22%2C%22cityId%22%3A30%2C%22searchType%22%3A%22CT%22%7D; __utmz=1.1744293928.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); _gac_UA-109672825-1=1.1744292488.Cj0KCQjw2N2_BhCAARIsAK4pEkVeqZGW4PbXLthdLy-fb8v01hb7qSRjy8mugoeBA0TmMwllARLZiyUaAhA8EALw_wcB; ibu_online_home_language_match={\"isRedirect\":false,\"isShowSuggestion\":false,\"lastVisited\":true,\"region\":\"us\",\"redirectSymbol\":false}; trip_test_cookie=1; _combined=transactionId%3D1-mf-20250411002925029-nodejs%26pageId%3D10320667453%26initPageId%3D10320667453; GUID=09034073116477340659; trn_traffic_start=10650138510; trn_traffic_end=10650138510; ibu_car_channelid=14409; _pd=%7B%22_o%22%3A17%2C%22s%22%3A24%2C%22_s%22%3A0%7D; __utma=1.1336250925.1744269840.1744293928.1744302731.2; __utmc=1; __utmb=1.2.10.1744302731; _ga_37RNVFDP1J=GS1.2.1744302674.3.1.1744302738.60.0.0; IBU_TRANCE_LOG_P=87772816003; oldLocale=zh-HK; IBU_showtotalamt=0; _uetsid=c603a9a015dc11f09485af91c9d176ee; _uetvid=c603df8015dc11f08e609db5bae96301; ttcsid=1744302675521.5.1744302753233; _ga=GA1.1.1336250925.1744269840; _ga_2DCSB93KS4=GS1.2.1744302674.5.1.1744302753.45.0.0; wcs_bt=s_33fb334966e9:1744302754; ttcsid_CIR4RVBC77UD5V58BBNG=1744302675520.5.1744303788223; _ga_X437DZ73MR=GS1.1.1744302674.5.1.1744303791.57.0.0; ibu_hotel_search_crn_guest=%7B%22adult%22%3A%222%22%2C%22children%22%3A%220%22%2C%22ages%22%3A%22%22%2C%22crn%22%3A%221%22%7D; _bfa=1.1744269722470.3595LWgSFeja.1.1744302746053.1744303792577.5.13.10320668148",
        "Referer": "https://hk.trip.com/hotels/list?city=30&cityName=%E6%B7%B1%E5%9C%B3&provinceId=0&countryId=1&districtId=0&checkin=2025%2F04%2F11&checkout=2025%2F05%2F05&lowPrice=0&highPrice=-1&barCurr=HKD&searchType=CT&searchWord=%E6%B7%B1%E5%9C%B3&crn=1&adult=2&children=0&searchBoxArg=t&travelPurpose=0&ctm_ref=ix_sb_dl&domestic=true&listFilters=29%7C1*29*1%7C2*2&locale=zh-HK&curr=HKD",
        "Referrer-Policy": "strict-origin-when-cross-origin"
    },
    "body": JSON.stringify(data)
    , "method": "POST"
}).then(response => {
    console.log(response);
    if (!response.ok) {
        throw new Error('网络请求失败');
    }
    return response.json(); // 解析 JSON 数据
}).then(data => {
    console.dir(data); // 获取最终数据
}).catch(error => {
    console.error('请求错误:', error);
});

